package com.offer;

import com.bean.ListNode;

/**
 * @Author: huangzhigao
 * @Date: 2023/3/4 17:32
 */
public class offer22 {
    public ListNode getKthFromEnd(ListNode head, int k) {
        ListNode dummy = new ListNode();
        dummy.next = head;
        ListNode p1 = dummy;
        ListNode p2 = dummy;
        for (int i = 0; i < k; i++) {
            p1 = p1.next;
        }

        while (p1 != null) {
            p2 = p2.next;
            p1 = p1.next;
        }
        return p2;
    }
}
